package com.my.ycv51.ycinit.mgr;

import android.os.Parcel;
import android.os.Parcelable;

import com.cloudwalk.android.CWDefine;
import com.my.ycv51.ycinit.config.Constants;

/**
 * @author YCKJ0827
 */
public class CwStoreMgr {

    public static class CameraOpenEntry implements Parcelable {

        private int openMode;

        private int cameraType;

        private String rgbPid;

        private String irPid;

        private String rgbVid;

        private String irVid;

        private boolean isRgbOpen;

        private boolean isIrOpen;

        public CameraOpenEntry() {
        }

        public CameraOpenEntry(int openType, String rgbPid, String irPid, String rgbVid, String irVid, boolean isRgbOpen, boolean isIrOpen) {
            this.openMode = openType;
            this.rgbPid = rgbPid;
            this.irPid = irPid;
            this.rgbVid = rgbVid;
            this.irVid = irVid;
            this.isRgbOpen = isRgbOpen;
            this.isIrOpen = isIrOpen;
        }

        public CWDefine.CWEnumCameraOpenMode getOpenMode() {
            return CWDefine.CWEnumCameraOpenMode.values()[openMode];
        }

        public void setOpenMode(CWDefine.CWEnumCameraOpenMode openMode) {
            this.openMode = openMode.ordinal();
        }

        public String getRgbPid() {
            return rgbPid;
        }

        public void setRgbPid(String rgbPid) {
            this.rgbPid = rgbPid;
        }

        public String getIrPid() {
            return irPid;
        }

        public void setIrPid(String irPid) {
            this.irPid = irPid;
        }

        public String getRgbVid() {
            return rgbVid;
        }

        public void setRgbVid(String rgbVid) {
            this.rgbVid = rgbVid;
        }

        public String getIrVid() {
            return irVid;
        }

        public void setIrVid(String irVid) {
            this.irVid = irVid;
        }

        public boolean isRgbOpen() {
            return isRgbOpen;
        }

        public void setRgbOpen(boolean rgbOpen) {
            isRgbOpen = rgbOpen;
        }

        public boolean isIrOpen() {
            return isIrOpen;
        }

        public void setIrOpen(boolean irOpen) {
            isIrOpen = irOpen;
        }

        protected CameraOpenEntry(Parcel in) {
            openMode = in.readInt();
            cameraType = in.readInt();
            rgbPid = in.readString();
            irPid = in.readString();
            rgbVid = in.readString();
            irVid = in.readString();
            isRgbOpen = in.readByte() != 0;
            isIrOpen = in.readByte() != 0;
        }

        public static final Creator<CameraOpenEntry> CREATOR = new Creator<CameraOpenEntry>() {
            @Override
            public CameraOpenEntry createFromParcel(Parcel in) {
                return new CameraOpenEntry(in);
            }

            @Override
            public CameraOpenEntry[] newArray(int size) {
                return new CameraOpenEntry[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeInt(openMode);
            parcel.writeInt(cameraType);
            parcel.writeString(rgbPid);
            parcel.writeString(irPid);
            parcel.writeString(rgbVid);
            parcel.writeString(irVid);
            parcel.writeByte((byte) (isRgbOpen ? 1 : 0));
            parcel.writeByte((byte) (isIrOpen ? 1 : 0));
        }
    }

    public CameraOpenEntry getCameraOpenEntry() {
        return new CameraOpenEntry(1, Constants.DEFAULT_RGB_PID, Constants.DEFAULT_IR_PID, Constants.DEFAULT_RGB_VID, Constants.DEFAULT_IR_VID, true, true);
    }
//
//    public void saveCameraOpenEntry(CameraOpenEntry mCameraOpenEntry) {
//        MMKV.defaultMMKV().encode(Constants.KEY_OPEN_CAMERA_SETTINGS, mCameraOpenEntry);
//    }
//
//    public void saveIsNeedReopenCamera(boolean isNeedReopen) {
//        MMKV.defaultMMKV().encode(Constants.KEY_IS_NEED_REOPEN_CAMERA, isNeedReopen);
//    }
//
//    public boolean getIsNeedReopenCamera() {
//        return MMKV.defaultMMKV().decodeBool(Constants.KEY_IS_NEED_REOPEN_CAMERA, false);
//    }
//
//    public void saveIsNeedReinitEngine(boolean isNeedReinit) {
//        MMKV.defaultMMKV().encode(Constants.KEY_IS_NEED_REINIT_ENGINE, isNeedReinit);
//    }
//
//    public boolean getIsNeedReinitEngine() {
//        return MMKV.defaultMMKV().decodeBool(Constants.KEY_IS_NEED_REINIT_ENGINE, false);
//    }

    public static class CameraParametersEntry implements Parcelable {

        private int width;

        private int height;

        public CameraParametersEntry() {
        }

        public CameraParametersEntry(int width, int height) {
            this.width = width;
            this.height = height;
        }

        public int getWidth() {
            return width;
        }

        public void setWidth(int width) {
            this.width = width;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        protected CameraParametersEntry(Parcel in) {
            width = in.readInt();
            height = in.readInt();
        }

        public static final Creator<CameraParametersEntry> CREATOR = new Creator<CameraParametersEntry>() {
            @Override
            public CameraParametersEntry createFromParcel(Parcel in) {
                return new CameraParametersEntry(in);
            }

            @Override
            public CameraParametersEntry[] newArray(int size) {
                return new CameraParametersEntry[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeInt(width);
            parcel.writeInt(height);
        }
    }

//    public CameraParametersEntry getCameraParametersEntry() {
//        return MMKV.defaultMMKV().decodeParcelable(Constants.KEY_CAMERA_PARAMETER_SETTINGS,
//                CameraParametersEntry.class,
//                new CameraParametersEntry(640, 480));
//    }
//
//    public void saveCameraParametersEntry(CameraParametersEntry mCameraParametersEntry) {
//        MMKV.defaultMMKV().encode(Constants.KEY_CAMERA_PARAMETER_SETTINGS, mCameraParametersEntry);
//    }

    public static class CameraPreviewParameterEntry implements Parcelable {
        private int mPreviewAngle;

        private int mPreviewMirror;

        public CameraPreviewParameterEntry() {
        }

        public CameraPreviewParameterEntry(int mPreviewAngle, int isOpenMirror) {
            this.mPreviewAngle = mPreviewAngle;
            this.mPreviewMirror = isOpenMirror;
        }

        public CWDefine.CWEnumCameraDataAngle getmPreviewAngle() {
            return CWDefine.CWEnumCameraDataAngle.valueOf(mPreviewAngle);
        }

        public void setmPreviewAngle(CWDefine.CWEnumCameraDataAngle mPreviewAngle) {
            this.mPreviewAngle = mPreviewAngle.getValue();
        }

        public void setmPreviewAngle(int mPreviewAngle) {
            this.mPreviewAngle = mPreviewAngle;
        }

        public CWDefine.CWEnumCameraDataMirror getmPreviewMirror() {
            return CWDefine.CWEnumCameraDataMirror.values()[mPreviewMirror];
        }

        public void setmPreviewMirror(CWDefine.CWEnumCameraDataMirror mirror) {
            mPreviewMirror = mirror.ordinal();
        }

        public void setmPreviewMirror(int mirror) {
            mPreviewMirror = mirror;
        }

        protected CameraPreviewParameterEntry(Parcel in) {
            mPreviewAngle = in.readInt();
            mPreviewMirror = in.readInt();
        }

        public static final Creator<CameraPreviewParameterEntry> CREATOR = new Creator<CameraPreviewParameterEntry>() {
            @Override
            public CameraPreviewParameterEntry createFromParcel(Parcel in) {
                return new CameraPreviewParameterEntry(in);
            }

            @Override
            public CameraPreviewParameterEntry[] newArray(int size) {
                return new CameraPreviewParameterEntry[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeInt(mPreviewAngle);
            parcel.writeInt(mPreviewMirror);
        }
    }

//    public CameraPreviewParameterEntry getCameraPreviewParameterEntry() {
//        return MMKV.defaultMMKV().decodeParcelable(Constants.KEY_CAMERA_PREVIEW_SETTINGS,
//                CameraPreviewParameterEntry.class, new CameraPreviewParameterEntry(90, 1));
//    }
//
//    public void saveCameraPreviewParameterEntry(CameraPreviewParameterEntry mCameraPreviewParameterEntry) {
//        MMKV.defaultMMKV().encode(Constants.KEY_CAMERA_PREVIEW_SETTINGS, mCameraPreviewParameterEntry);
//    }
//
//    public CWSDKParamBean getSDKParameters() {
//        return MMKV.defaultMMKV().decodeParcelable(Constants.KEY_LIVE_SETTINGS,
//                CWSDKParamBean.class, new CWSDKParamBean());
//    }
//
//    public void saveSDKParameters(CWSDKParamBean mCWSDKParamBean) {
//        MMKV.defaultMMKV().encode(Constants.KEY_LIVE_SETTINGS, mCWSDKParamBean);
//    }

    public static class FileConfigEntry implements Parcelable {

        private boolean isOpenSaveImage = false;

        private String saveImagePath = "...";

        private boolean isOpenFaceMask = false;

        private String faceMaskPath = "...";

        private String theBestFaceRatio = "2";

        private String modelPath = "/data/local/tmp/assets/";

        public FileConfigEntry() {
        }

        public boolean isOpenSaveImage() {
            return isOpenSaveImage;
        }

        public void setOpenSaveImage(boolean openSaveImage) {
            isOpenSaveImage = openSaveImage;
        }

        public String getSaveImagePath() {
            return saveImagePath;
        }

        public void setSaveImagePath(String saveImagePath) {
            this.saveImagePath = saveImagePath;
        }

        public boolean isOpenFaceMask() {
            return isOpenFaceMask;
        }

        public void setOpenFaceMask(boolean openFaceMask) {
            isOpenFaceMask = openFaceMask;
        }

        public String getFaceMaskPath() {
            return faceMaskPath;
        }

        public void setFaceMaskPath(String faceMaskPath) {
            this.faceMaskPath = faceMaskPath;
        }

        public String getTheBestFaceRatio() {
            return theBestFaceRatio;
        }

        public void setTheBestFaceRatio(String theBestFaceRatio) {
            this.theBestFaceRatio = theBestFaceRatio;
        }

        public String getModelPath() {
            return modelPath;
        }

        public void setModelPath(String modelPath) {
            this.modelPath = modelPath;
        }

        protected FileConfigEntry(Parcel in) {
            isOpenSaveImage = in.readByte() != 0;
            saveImagePath = in.readString();
            isOpenFaceMask = in.readByte() != 0;
            faceMaskPath = in.readString();
            theBestFaceRatio = in.readString();
            modelPath = in.readString();
        }

        public static final Creator<FileConfigEntry> CREATOR = new Creator<FileConfigEntry>() {
            @Override
            public FileConfigEntry createFromParcel(Parcel in) {
                return new FileConfigEntry(in);
            }

            @Override
            public FileConfigEntry[] newArray(int size) {
                return new FileConfigEntry[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeByte((byte) (isOpenSaveImage ? 1 : 0));
            parcel.writeString(saveImagePath);
            parcel.writeByte((byte) (isOpenFaceMask ? 1 : 0));
            parcel.writeString(faceMaskPath);
            parcel.writeString(theBestFaceRatio);
            parcel.writeString(modelPath);
        }
    }

//    public FileConfigEntry getFileConfigEntry() {
//        return MMKV.defaultMMKV().decodeParcelable(Constants.KEY_FILE_CONFIG_SETTINGS,
//                FileConfigEntry.class, new FileConfigEntry());
//    }
//
//    public void saveFileConfigEntry(FileConfigEntry fileConfigEntry) {
//        MMKV.defaultMMKV().encode(Constants.KEY_FILE_CONFIG_SETTINGS, fileConfigEntry);
//    }

    public static class RecognizeScannerModeEntry implements Parcelable {

        private String recognizeThreshold = "0.85";

        private boolean requireScannerMode;

        public RecognizeScannerModeEntry() {
        }

        public String getRecognizeThreshold() {
            return recognizeThreshold;
        }

        public void setRecognizeThreshold(String recognizeThreshold) {
            try {
                float v = Float.parseFloat(recognizeThreshold);
                if (v < 0.0f || v > 1.0f) {
                    return;
                }
            } catch (NumberFormatException e) {
                return;
            }
            this.recognizeThreshold = recognizeThreshold;
        }

        public boolean isRequireScannerMode() {
            return requireScannerMode;
        }

        public void setRequireScannerMode(boolean requireScannerMode) {
            this.requireScannerMode = requireScannerMode;
        }

        protected RecognizeScannerModeEntry(Parcel in) {
            recognizeThreshold = in.readString();
            requireScannerMode = in.readByte() != 0;
        }

        public static final Creator<RecognizeScannerModeEntry> CREATOR = new Creator<RecognizeScannerModeEntry>() {
            @Override
            public RecognizeScannerModeEntry createFromParcel(Parcel in) {
                return new RecognizeScannerModeEntry(in);
            }

            @Override
            public RecognizeScannerModeEntry[] newArray(int size) {
                return new RecognizeScannerModeEntry[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeString(recognizeThreshold);
            parcel.writeByte((byte) (requireScannerMode ? 1 : 0));
        }
    }

//    public RecognizeScannerModeEntry getRecognizeScannerModeEntry() {
//        return MMKV.defaultMMKV().decodeParcelable(Constants.KEY_THRESHOLD_SCANNER_MODE,
//                RecognizeScannerModeEntry.class, new RecognizeScannerModeEntry());
//    }
//
//    public void saveRecognizeScannerModeEntry(RecognizeScannerModeEntry recognizeScannerModeEntry) {
//        MMKV.defaultMMKV().encode(Constants.KEY_THRESHOLD_SCANNER_MODE, recognizeScannerModeEntry);
//    }
//
//    public String getAppVersion() {
//        return MMKV.defaultMMKV().decodeString(Constants.KEY_APP_VERSION, null);
//    }
//
//    public void saveAppVersion(String version) {
//        MMKV.defaultMMKV().encode(Constants.KEY_APP_VERSION, version);
//    }

}
